package edu.bit.water.service;

import edu.bit.water.dao.MetaCleanProductSub5Dao;
import edu.bit.water.entity.MetaCleanProductSub5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MetaCleanProductSub5Service {
    @Autowired
    private MetaCleanProductSub5Dao metaCleanProductSub5Dao;

    // 查询
    public List<MetaCleanProductSub5> select(int lastId) {
        List<MetaCleanProductSub5> list = metaCleanProductSub5Dao.select(lastId);
        return list;
    }

    // 新增
    public Map<String, Object> insert(MetaCleanProductSub5 metaCleanProductSub5) {
        Map<String, Object> map = new HashMap<>();
        int n = metaCleanProductSub5Dao.insert(metaCleanProductSub5);
        if (n == 1) {
            map.put("status", "success");
        } else {
            map.put("status", "failed");
        }
        return map;
    }

    // 编辑
    public Map<String, Object> update(MetaCleanProductSub5 metaCleanProductSub5) {
        Map<String, Object> map = new HashMap<>();
        int n = metaCleanProductSub5Dao.update(metaCleanProductSub5);
        if (n == 1) {
            map.put("status", "success");
        } else {
            map.put("status", "failed");
        }
        return map;
    }

    // 删除
    public int delete(List<Integer> ids) {
        try {
            for (Integer id : ids) {
                metaCleanProductSub5Dao.delete(id);
            }
            return 1;
        } catch (Exception e) {
            return 0;
        }

    }
}
